home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / 07 attributes / attributesdemo / classes.vb < prev    next >
Text File  |  2002-03-16  |  2KB  |  66 lines

  1. Imports System.Runtime.InteropServices
  2.  
  3. ' this structure shows that you can map multiple values at the
  4. ' same offset in memory
  5.  
  6. <StructLayout(LayoutKind.Explicit)> _
  7. Structure ARGBColor
  8.     <FieldOffset(0)> Dim Red As Byte
  9.     <FieldOffset(1)> Dim Green As Byte
  10.     <FieldOffset(2)> Dim Blue As Byte
  11.     <FieldOffset(3)> Dim Alpha As Byte
  12.  
  13.     <FieldOffset(0)> Dim Value As Integer
  14. End Structure
  15.  
  16. ' a structure for converting integer data types
  17.  
  18. <StructLayout(LayoutKind.Explicit)> _
  19. Structure IntegerTypes
  20.     ' A 64-bit integer
  21.     <FieldOffset(0)> Dim Long0 As Long
  22.     ' Two 32-bit integers
  23.     <FieldOffset(0)> Dim Integer0 As Integer
  24.     <FieldOffset(4)> Dim Integer1 As Integer
  25.     ' Four 16-bit integers
  26.     <FieldOffset(0)> Dim Short0 As Short
  27.     <FieldOffset(2)> Dim Short1 As Short
  28.     <FieldOffset(4)> Dim Short2 As Short
  29.     <FieldOffset(6)> Dim Short3 As Short
  30.     ' Eight 8-bit integers
  31.     <FieldOffset(0)> Dim Byte0 As Byte
  32.     <FieldOffset(1)> Dim Byte1 As Byte
  33.     <FieldOffset(2)> Dim Byte2 As Byte
  34.     <FieldOffset(3)> Dim Byte3 As Byte
  35.     <FieldOffset(4)> Dim Byte4 As Byte
  36.     <FieldOffset(5)> Dim Byte5 As Byte
  37.     <FieldOffset(6)> Dim Byte6 As Byte
  38.     <FieldOffset(7)> Dim Byte7 As Byte
  39.  
  40.     ' Low byte of a word
  41.     Function LowByte(ByVal Value As Long) As Byte
  42.         Long0 = Value
  43.         Return Byte0
  44.     End Function
  45.  
  46.     ' High byte of a word
  47.     Function HighByte(ByVal Value As Long) As Byte
  48.         Long0 = Value
  49.         Return Byte1
  50.     End Function
  51.  
  52.     ' Low word of a doubleword
  53.     Function LowWord(ByVal Value As Long) As Short
  54.         Long0 = Value
  55.         Return Short0
  56.     End Function
  57.  
  58.     ' High word of a doubleword
  59.     Function HighWord(ByVal Value As Long) As Short
  60.         Long0 = Value
  61.         Return Short1
  62.     End Function
  63.  
  64. End Structure
  65.  
  66.